<template>
  <div>
    <v-nav :current="3" :isEnShow="false"></v-nav>
    <img src="@/components/xinwen.png" alt="" style="width: 100%">
    <!-- <h1>公司公告</h1>
    <div style="height: 16px;background-color: #f5f5f5"></div> -->
    <h1>推荐新闻</h1>
    <div class="lists" v-for="list in liststj" :key="list.id" @click="toDetails(list.id)">
      <div>
        <h2>{{list.post_title}}</h2>
        <span>时间：{{list.time}}</span>
      </div>
      <img :src="list.src" alt="">
    </div>
    <div style="height: 16px;background-color: #f5f5f5"></div>
    <h1>新闻中心</h1>
    <div class="lists" v-for="list in lists" :key="list.id" @click="toDetails(list.id)">
      <div>
        <h2>{{list.post_title}}</h2>
        <span>时间：{{list.time}}</span>
      </div>
      <img :src="list.src" alt="">
    </div>
    <div class="space73"></div>
    <div style="display:flex;justify-content: center;" class="fenye">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :page-size="6"
        :small="true"
        @current-change="handleCurrentChanges"
        >
      </el-pagination>
    </div>
    <div class="space73"></div>
    <v-footer></v-footer>
  </div>
</template>

<script>
import vNav from '@/components/nav/nav'
import vFooter from '@/components/footer'
import {mapGetters} from 'vuex'
import { getNewsData, getTuiJianData } from '@/services/api.js'
export default {
  name: 'news',
  data () {
    return {
      total: null,
      lists: [],
      liststj: [],
      page: 1
    }
  },
  computed: {
    ...mapGetters({
      'lang': 'lang'
    })
  },
  components: {
    vNav,
    vFooter
  },
  methods: {
    toDetails (id) {
      this.$router.push({name: 'newsDetails', params: {id: id}})
    },
    _getChList (searchWord) {
      this.title = '新闻中心'
      this.details = '查看详情'
      this.recommend = '推荐新闻'
      this.Announcement = '公司公告'
      let params = {
        page: this.page
      }
      getNewsData(params).then((res) => {
        console.log(res)
        this.lists = res.data
        this.total = res.total
      })
      getTuiJianData().then((res) => {
        console.log(res)
        this.liststj = res
      })
    },
    _getEnList () {
      this.title = 'News Center'
      this.details = 'details'
      this.recommend = 'Recommend News'
      this.Announcement = 'Announcement'
      this.lists = [
        {
          id: 1,
          name: 'sdf dsgdg dfgdf ddbdsw sfs2'
        },
        {
          id: 2,
          name: 'sdf dsgdg dfgdf ddbdsw sfs2'
        },
        {
          id: 3,
          name: 'sdf dsgdg dfgdf ddbdsw sfs2'
        }
      ]
    },
    handleCurrentChanges (val) {
      this.page = val
      let params = {
        page: this.page
      }
      getNewsData(params).then((res) => {
        console.log(res)
        this.lists = res.data
        this.total = res.total
      })
    },
    version () {
      if (this.lang === 1) {
        this._getChList()
      }
      if (this.lang === 2) {
        this._getEnList()
      }
    }
  },
  created () {
    this.version()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import '../util/common.scss';
h1 {
  padding: 36rem/$font-size-base 0;
  font-size: 30rem/$font-size-base;
  letter-spacing: 1px;
  color: #333;
  font-weight: bolder;
  text-align: left;
  padding-left: 30rem/$font-size-base;
  font-weight: normal;
}
.lists {
  display: flex;
  padding: 30rem/$font-size-base;
  border-top: 1px solid #e6e6e6;
  justify-content: space-between;
  div {
    width: 416rem/$font-size-base;
    h2 {
      font-size: 26rem/$font-size-base;;
      letter-spacing: 2px;
      color: #333;
      margin-bottom: 63rem/$font-size-base;
    }
    span {
      font-size: 22rem/$font-size-base;
      color: #808080;
    }
  }
  img {
    width: 240rem/$font-size-base;
    height: 160rem/$font-size-base;
  }
}
.lists:last-child {
  border-bottom: 1px solid #e6e6e6;
}
.space73 {
  width: 100%;
  height: 30rem/$font-size-base;
  background-color: #fff
}
</style>
